#!/bin/bash
#DolphinDB Server Upgrade Off-line
set -e
echo "Tip: please back up metadata before upgrade!"
read -p "Have you backed up metadata?(yes/no)" answer
if [[ ${answer} == *yes* ]];then
   	read -p "Please select upgrade version:" realease
    echo "Start to unzip DolphinDB_Linux64_V${realease}.zip"
    unzip "DolphinDB_Linux64_V${realease}.zip" -d "v${realease}"
    echo "unzip succeeded!"
    echo "Start to upgrade!"
    echo "DolphinDB server upgrading ........"
    cd server/
    rm lib* -f
    cp ../"v${realease}"/server/lib* ./ -f
    rm dolphindb -f
    cp ../"v${realease}"/server/dolphindb ./ -f
    chmod 777 dolphindb
    rm dolphindb.dos -f
    cp ../"v${realease}"/server/dolphindb.dos ./ -f
    cp -r ../"v${realease}"/server/plugins/ ./ -f
    rm web -rf 
    cp -r ../"v${realease}"/server/web ./ -f
    cd ..
    rm "v${realease}" -rf
    echo "Upgrade succeeded, please check!"    
else
	echo "please back up metadata before upgrade!"
fi